@echo off
:: 2024-11-03 15:45:26
:: =================================
::	"Microsoft Office LTSC 專業增強版 2024"
::	DownloadOffice2024.cmd	2024-10-30 20:59:33
::
::	Office Deployment Tool
::	https://www.microsoft.com/en-us/download/details.aspx?id=49117
::
::	設定 KMS 主機電腦以啟用大量授權版本的 Office
::	https://learn.microsoft.com/zh-tw/deployoffice/vlactivation/configure-a-kms-host-computer-for-office
::
:: ====
::	November 21, 2023	11/22/2023
::	set "URLFile=https://download.microsoft.com/download/2/7/A/27AF1BE6-DD20-4CB4-B154-EBAB8A7D4A7E/officedeploymenttool_16731-20398.exe"
::	set "Version=16.0.16731.20398"
::	set "DatePublished=11/22/2023"
::	set "FileName=officedeploymenttool_16731-20398.exe"
::
::	%Public%\Downloads\OfficeProPlus2024\16.0.16731.20398\Office\Data\v64_16.0.14332.20604.cab
::	set "OfficeData=16.0.14332.20604"
::	set "DataFileSize=1.78 GB"
:: =================================

if "%~1"=="" (
	set "EndCmd=k"
) else (
	set "EndCmd=%~1"
)

rem ====----	AutoToRun
if "%~2"=="" (
	set /a AutoToRun=0
) else (
	set "AutoToRun=1"
)

rem ====	基本系統設定 set 一定要加""避免空白
set "Driver=%~d0"
set "FilePath=%~p0"
set "ConfFile=%~n0"
set "FullPath=%~dp0"
set "FullPathFile=%~f0"

title %~nx0

rem ====----	IsAdmin
call :IsAdmin

cd /D "%Driver%%FilePath%"
rem ==--

rem ====----	1.	Config_ini
set "ConfFile=%~n0"
set "Config_ini=%Driver%%FilePath%%ConfFile%.ini"

rem ====	Read Config_ini
call :ReadiniFile

rem ====----	2.	Set Variable name
call :SetVariable

rem ====	Code page
For /f "tokens=2 delims=:" %%G in ('chcp') do set chcp_Code=%%G

rem ====	language
call :MsgSet

rem ====	ColorSet
call :ColorSet

rem ====----	3.	Download Offiec 2024. ODT is Office Deployment Tool

if %AutoToRun% EQU 0 (
	call :SeleToRun "%Input_ODT%"
) else (
	set /a IsToRun=1
)

if %IsToRun% NEQ 0 (
	rem ====	Download ODT
	call :RunCurl
	call :SetupExtractXml
	call :CreateXMLConfig
)

rem %ExtractPath%\setup.exe /download %xmlFile%
if %AutoToRun% EQU 0 (
	call :SeleToRun "%Input_Msg%"
) else (
	set /a IsToRun=1
)

rem ====---- Office 2024 2.52G
if %IsToRun% NEQ 0 (
	call :SetupDownloadXml
)

rem ====----	OfficeData
call :GetOfficeData

rem ====----	MkLink
rem  C:\Users\Public\desktop\ProPlus2024Volume\16.0.15330.20306 的符號連結 <<===>> C:\Users\Public\Downloads\ProPlus2024Volume\16.0.15330.20306
call :RunMkLink

rem %ExtractPath%\setup.exe /configure %xmlFile%
rem ====----	4.	Install Office 2024
if not exist "%ProgramFiles%\Microsoft Office\root\Office16\misc.exe" (
	call :SetupConfigXml
)

rem ====----	5.	Activate Office
if exist "%ProgramFiles%\Microsoft Office\Office16\ospp.vbs" (
	call :Activate
	call :Sel_Server
	rem ====----	6.	CopyLink and Status
	call :CopyLink
	call :ShortcutActivate
	call :CD_Office16
	call :Dstatus
) else (
	call :OsppvbsError
)

rem ====----	7.	Reinstall Office 2024
if not exist "%ExtractPath%\%Product_ID%.bat" (
	goto END
)

set /a IsToRun=0
echo.

if %AutoToRun% EQU 0 (
	call :SeleToRun "%Input_runMsg%"
)

if %IsToRun% NEQ 0 (
	if %AutoToRun% EQU 0 (
		call :SetupConfigXml
		timeout /t 10
	)
)

rem ====----	8.	Retail-to-Volume

if %Product_ID% EQU O365ProPlusRetail (
	rem ====----	Download Retail-to-Volume AIO
	call :C2R-R2V-AIO
	rem ====----	Run Retail-to-Volume AIO
	call C2R-R2V-AIO.cmd
)

rem ====----	9.	End
goto END

:ColorSet
	rem ==== 2 Normal Background
	set "ClolorBlue_NB=[44m"
	set "ClolorMagenta_NB=[45m"
	rem ==== 3 Bright Text
	set "ClolorGreen_BT=[92m"
	set "ClolorYellow_BT=[93m"
	set "ClolorMagenta_BT=[95m"
	rem ==== 0 DefaultClolor
	set "DefaultClolor=[0m"
	exit /b

:MsgSet
	rem echo %chcp_Code%
	if /i %chcp_Code% EQU 950 (
		set "Input_ODT=你要下載 Office Deployment Tool 的安裝程式嗎 ? 輸入 yes 或 no (y/n):[0m [0m"
		set "Input_Msg=你要下載 %OfficeProductFullName% 的程式嗎 ? 輸入 yes 或 no (y/n):[0m [0m"
		set "Input_runMsg=你要執行安裝Office的 %Product_ID%.bat 嗎 ? 輸入 yes 或 no (y/n):[0m [0m"
	) else (
		set "Input_ODT=Do you want to download the Office Deployment Tool installer? Enter yes or no (y/n):[0m [0m"
		set "Input_Msg=Do you want to download the %OfficeProductFullName% program? Enter yes or no (y/n):[0m [0m"
		set "Input_runMsg=Do you want to execute %Product_ID%.bat to install Office? Enter yes or no (y/n):[0m [0m"
	)
	exit /b

:SeleToRun
	set Input_ToRun=
	set /a IsToRun=0
	set SeleToRun_MSG=%~1%
	set /p Input_ToRun=%ClolorMagenta_NB%%SeleToRun_MSG%%DefaultClolor%
	if not '%Input_ToRun%'=='' set Input_ToRun=%Input_ToRun:~0,1%
	if /i '%Input_ToRun%'=='y' (
		set /a IsToRun+=1
	) else (
		set /a IsToRun=0
	)
	if '%Input_ToRun%'=='' (
		set /a IsToRun=0
	)
	exit /b

:CreateXMLConfig
	if not exist %ExtractPath%\nul (
		mkdir %ExtractPath%
		echo.
	)
	echo ^<Configuration ID="%Configuration_ID%"^> >%xmlFile%
	echo   ^<Add OfficeClientEdition="64" Channel="%Channel%"^> >>%xmlFile%
	echo     ^<Product ID="%Product_ID%" PIDKEY="%PIDKEY%"^> >>%xmlFile%
	echo       ^<Language ID="%Language_ID%" /^> >>%xmlFile%
	echo       ^<ExcludeApp ID="Groove" /^> >>%xmlFile%
	echo       ^<ExcludeApp ID="Lync" /^> >>%xmlFile%
	echo     ^</Product^> >>%xmlFile%
	echo   ^</Add^> >>%xmlFile%
	echo   ^<Property Name="SharedComputerLicensing" Value="1" /^> >>%xmlFile%
	echo   ^<Property Name="FORCEAPPSHUTDOWN" Value="FALSE" /^> >>%xmlFile%
	echo   ^<Property Name="DeviceBasedLicensing" Value="0" /^> >>%xmlFile%
	echo   ^<Property Name="SCLCacheOverride" Value="0" /^> >>%xmlFile%
	echo   ^<Property Name="AUTOACTIVATE" Value="1" /^> >>%xmlFile%
	echo   ^<Updates Enabled="TRUE" /^> >>%xmlFile%
	echo   ^<RemoveMSI /^> >>%xmlFile%

	echo     ^<AppSettings^> >>%xmlFile%
	echo       ^<User Key="software\microsoft\office\16.0\excel\options" Name="defaultformat" Value="51" Type="REG_DWORD" App="excel16" Id="L_SaveExcelfilesas" /^> >>%xmlFile%
	echo       ^<User Key="software\microsoft\office\16.0\powerpoint\options" Name="defaultformat" Value="27" Type="REG_DWORD" App="ppt16" Id="L_SavePowerPointfilesas" /^> >>%xmlFile%
	echo       ^<User Key="software\microsoft\office\16.0\word\options" Name="defaultformat" Value="" Type="REG_SZ" App="word16" Id="L_SaveWordfilesas" /^> >>%xmlFile%
	echo     ^</AppSettings^> >>%xmlFile%

	echo ^</Configuration^> >>%xmlFile%
	exit /b

:GetOfficeData
	For /f "tokens=2 delims=_" %%I in ('dir %ExtractPath%\Office\Data\v64_*.cab /b') do (
		set OfficeData=%%I
	)
	set OfficeData=%OfficeData:~0,-4%
	echo 	OfficeData = %OfficeData%
	exit /b

:RunMkLink
	if exist %PUBLIC%\desktop\%OfficeProductName%\%Product_ID%\%Version% (
		rmdir /Q %PUBLIC%\desktop\%OfficeProductName%\%Product_ID%\%Version%
	) else (
		call :Checkdir "%PUBLIC%\desktop\%OfficeProductName%\%Product_ID%\"
	)
	mklink /D %PUBLIC%\desktop\%OfficeProductName%\%Product_ID%\%Version% "%ExtractPath%"
	exit /b

:SetupExtractXml
	rem ==== %HOMEDRIVE%%HOMEPATH%\Downloads\officedeploymenttool_16026-20170.exe  /extract:%extractPath% /quiet
	echo [92m"%PathFilename%"  /extract:"%extractPath%" /quiet [0m
	"%PathFilename%"  /extract:"%extractPath%" /quiet
	copy /Y  "%PathFilename%"  "%extractPath%" >nul

	%HOMEDRIVE%
	cd /D %extractPath%
	rem if not exist %ExtractPath%\%Product_ID%.bat (
		rem echo %ExtractPath%\setup.exe /configure %xmlFile% > %ExtractPath%\%Product_ID%.bat
		echo @echo off > %ExtractPath%\%Product_ID%.bat
		echo set "Driver=%%~d0" >> %ExtractPath%\%Product_ID%.bat
		echo set "FilePath=%%~p0" >> %ExtractPath%\%Product_ID%.bat
		echo echo [92m"%%Driver%%%%FilePath%%setup.exe" /configure "%%Driver%%%%FilePath%%%Product_ID%.xml"[0m >> %ExtractPath%\%Product_ID%.bat
		echo "%%Driver%%%%FilePath%%setup.exe" /configure "%%Driver%%%%FilePath%%%Product_ID%.xml" >> %ExtractPath%\%Product_ID%.bat
		if %Product_ID% EQU O365ProPlusRetail (
			echo call "%%Driver%%%%FilePath%%C2R-R2V-AIO.cmd" >> %ExtractPath%\%Product_ID%.bat
		)		
		echo exit /b >> %ExtractPath%\%Product_ID%.bat
		echo rem %ExtractPath% >> %ExtractPath%\%Product_ID%.bat
	rem )

	copy /Y  "%Product_ID%.bat"  "%extractPath%\Install.bat" >nul
	echo.
	exit /b

:SetupDownloadXml
	%HOMEDRIVE%
	cd %extractPath%
	echo Download Office Data:	%OfficeData%		Data File Size:	%DataFileSize%
	echo [92m"%ExtractPath%\setup.exe" /download "%xmlFile%"[0m
	"%ExtractPath%\setup.exe" /download "%xmlFile%"
	exit /b

:SetupConfigXml
	%HOMEDRIVE%
	cd %extractPath%
	echo [92m"%ExtractPath%\setup.exe" /configure "%xmlFile%"[0m
	"%ExtractPath%\setup.exe" /configure "%xmlFile%"
	exit /b

:Activate
	rem explorer "http://MSGuides.com" 2023-03-03
	title Activate Microsoft %OfficeProductName% ALL versions for FREE!	Run as administrator.
	echo.
	echo.[45m#Project: Activating Microsoft software products for FREE without software[0m
	echo.
	echo  #Supported products: %OfficeProductFullName%

	if exist "%ProgramFiles%\Microsoft Office\Office16\ospp.vbs" (
		cd /d "%ProgramFiles%\Microsoft Office\Office16"
	)
	if exist "%ProgramFiles(x86)%\Microsoft Office\Office16\ospp.vbs" (
		cd /d "%ProgramFiles(x86)%\Microsoft Office\Office16"
	)
	rem LicenseFiles
	for /f %%x in ('dir /b ..\root\Licenses16\%LicenseFiles%') do (
 		cscript ospp.vbs /inslic:"..\root\Licenses16\%%x"
	)
	cscript //nologo ospp.vbs /setprt:1688
	echo.
	echo  Activating your Office...
	cscript //nologo ospp.vbs /unpkey:%PIDKEY:~-5%
	echo.
	rem ProPlus2024Volume	Office LTSC Professional Plus 2024 - Volume License	FXYTK-NJJ8C-GB6DW-3DYQT-6F7TH
	cscript //nologo ospp.vbs /inpkey:%PIDKEY% || goto NotSupported
	echo.
	set i=1
	exit /b

:Sel_Server
	rem https://www.kms.pub/rank.html	2024-10-29

	rem if %i%==1 set KMS_Sev=kms.catqu.com
	rem if %i%==2 set KMS_Sev=kms.loli.beer
	rem if %i%==3 set KMS_Sev=kms.loli.best

	if %i%==1 set "KMS_Sev=%KMS_Sev_1%"
	if %i%==2 set "KMS_Sev=%KMS_Sev_2%"
	if %i%==3 set "KMS_Sev=%KMS_Sev_3%"
	if %i%==4 goto NotSupported
	echo %KMS_Sev%
	cscript //nologo ospp.vbs /sethst:%KMS_Sev%
	cscript //nologo ospp.vbs /act | find /i "Product activation successful"
	rem echo %errorlevel%
	if %errorlevel% equ 0 goto Halt
	echo The connection to %KMS_Sev% server failed! Trying to connect to another one...
	set /a i+=1
	rem LSS - less than
	if %i% LSS 5 (
		goto Sel_Server
	)
	exit /b

:NotSupported
	echo Sorry! Your version is not supported
	echo Please try installing the latest version here:
	echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	echo Unable to connect the server, failed to activation
	echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	goto End

:Halt
	echo ============================================================================
	echo  Microsoft %OfficeProductName% activation successful
	echo ============================================================================
	exit /b

:OsppvbsError
	if not exist "%ProgramFiles%\Microsoft Office\Office16\ospp.vbs" (
		echo Can not found %ProgramFiles%\Microsoft Office\Office16\ospp.vbs
		timeout /t 3
	)
	exit /b

:CD_Office16
	if exist "%ProgramFiles%\Microsoft Office\Office16\ospp.vbs" (
		cd /d "%ProgramFiles%\Microsoft Office\Office16"
	)
	if exist "%ProgramFiles(x86)%\Microsoft Office\Office16\ospp.vbs" (
		cd /d "%ProgramFiles(x86)%\Microsoft Office\Office16"
	)
	exit /b

:Dstatus
	echo [45mDstatus[0m

	cscript //nologo ospp.vbs /dstatus
	exit /b

:CopyLink
	rem ====	Copy Office lnk to Desktop
	if not exist "%PUBLIC%\desktop\%OfficeProductName%\" (
		mkdir "%PUBLIC%\desktop\%OfficeProductName%"
	)
	if exist "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Word.lnk" (
		if not exist "%PUBLIC%\desktop\%OfficeProductName%\Word.lnk" (
			copy  /Y "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Access.lnk"  "%PUBLIC%\desktop\%OfficeProductName%\"
			copy  /Y "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Excel.lnk"  "%PUBLIC%\desktop\%OfficeProductName%\"
			copy  /Y "%ProgramData%\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk"  "%PUBLIC%\desktop\%OfficeProductName%\"
			copy  /Y "%ProgramData%\Microsoft\Windows\Start Menu\Programs\OneNote.lnk"  "%PUBLIC%\desktop\%OfficeProductName%\"
			copy  /Y "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Outlook*.lnk"  "%PUBLIC%\desktop\%OfficeProductName%\"
			copy  /Y "%ProgramData%\Microsoft\Windows\Start Menu\Programs\PowerPoint.lnk"  "%PUBLIC%\desktop\%OfficeProductName%\"
			copy  /Y "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Publisher.lnk"  "%PUBLIC%\desktop\%OfficeProductName%\"
			copy  /Y "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Word.lnk"  "%PUBLIC%\desktop\%OfficeProductName%\"
			dir "%PUBLIC%\desktop\%OfficeProductName%\*.lnk"
		)
	)
	exit /b

:ShortcutActivate
	rem ====	Microsoft %OfficeProductName% Activate.zip
	if exist %HOMEDRIVE%\PortableApps\Shortcut\Shortcut.exe (
		set "Shortcut=%HOMEDRIVE%\PortableApps\Shortcut\Shortcut.exe"
	) else (
		echo Can not find %HOMEDRIVE%\PortableApps\Shortcut\Shortcut.exe
		exit /b
	)

	if /i exist "%SystemDrive%\Program Files\Microsoft Office\root\Office16\1028\MSAIN.DLL" (
		call :Checkdir %PUBLIC%\desktop\%OfficeProductName%\
	) else (
		echo Can not find %SystemDrive%\Program Files\Microsoft Office\root\Office16\1028\MSAIN.DLL
		exit /b
	)

	if exist "%HOMEDRIVE%\PortableApps\Microsoft Office Activate\Activate %ActivateFileVer%.cmd" (
		rem C:\PortableApps\Shortcut\Shortcut.exe  /T:"C:\PortableApps\Microsoft Office Activate\Activate Office 2024.cmd"  /F:"C:\Users\Public\desktop\Office 2024\Activate Office 2024.cmd.lnk"  /I:"C:\Program Files\Microsoft Office\root\Office16\1028\MSAIN.DLL"  /A:c
		%Shortcut%  /T:"%HOMEDRIVE%\PortableApps\Microsoft Office Activate\Activate %ActivateFileVer%.cmd"  /F:"%PUBLIC%\desktop\%OfficeProductName%\Activate %ActivateFileVer%.cmd.lnk"  /I:"%HOMEDRIVE%\Program Files\Microsoft Office\root\Office16\1028\MSAIN.DLL"  /A:c
		%Shortcut%  /T:"%HOMEDRIVE%\PortableApps\Microsoft Office Activate\Detect office activation status.cmd"  /F:"%PUBLIC%\desktop\%OfficeProductName%\Detect office activation status.cmd.lnk"  /I:"%HOMEDRIVE%\Program Files\Microsoft Office\root\vfs\ProgramFilesCommonX64\Microsoft Shared\OFFICE16\MSO.DLL"  /A:c
	)
	exit /b

:ReadiniFile
	rem ====----	setlocal enabledelayedexpansion
	rem ====----	Read ini File
	if not exist "%Config_ini%" (
		echo Cant Find %Config_ini%
		goto End
	)

	rem ====----	setlocal enabledelayedexpansion
	rem ====----	Read ini File
	rem ====	不可含()
	rem xxx set "FilePath=%O_FilePath:^(=^^(%"
	rem xxx set "FilePath=%O_FilePath:^)=^^)%"
	echo|set /p="[45m"
	echo ReadiniFile[0m
	echo|set /p="%Config_ini%"[0m
	echo|set /p="[0m"
	echo.

	rem  修path
	For /F "tokens=1* delims==" %%I in ('findstr /i  "^[A-z]" "%Config_ini%"') do (
		rem echo %%I %%J
		set "%%I=%%J"
	)
	setlocal enabledelayedexpansion
	For /F "tokens=1* delims==" %%I in ('findstr /i  "^[A-z]" "%Config_ini%"') do (
		rem echo %%I %%J
		rem ====	2024-08-28	()
		if defined %%I (
			set II=%%I
			::	Show only URL and Download
			if /i !II! EQU URL (echo 	%%I 	 = %%J)
			if /i !II! EQU Download (echo 	%%I = %%J)
			if /i !II! EQU Version (echo 	%%I  = %%J)
			if /i !II! EQU FileDate (echo 	%%I = %%J)
			if /i !II! EQU OfficeData (echo 	%%I   = %%J)
			if /i !II! EQU DataFileSize (echo 	%%I = %%J)
		)
	)
	setlocal
	echo.
	exit /b

:SetVariable
	rem ====----	Set Path Variable
	::	PathFilename
	::	InstallFilename
	::	DownloadPath

	::	ini AppName		Version			FileName
	::	ini UnZipFile	UnzipFolder		UnzipCopyFile	UnZipSetupExe
	::	ini	NotZipFile	ExeUnZip		PassWord
	::	ini	MediaFire	dButton

	::	ini LinkEnv		LinkFile		ToLinkFolder	ToLinkTarget
	::	ini ToRegistEnv	ToRegistFolder 	ToRegistFile

	::	ini RunXcopy ^(RoboCopy^)
	
	set "FileName=%FileName:^(=^^(%"
	set "FileName=%FileName:^)=^^)%"
	
	set "FilePath=%~p0"
	set "FilePath=%FilePath:^(=^^(%"
	set "FilePath=%FilePath:^)=^^)%"
	
	if defined UnzipFolder (
		set "UnzipFolder=%UnzipFolder:^(=^^(%"
		set "UnzipFolder=%UnzipFolder:^)=^^)%"
	)
	
	if defined UnZipFile (
		set "UnZipFile=%UnZipFile:^(=^^(%"
		set "UnZipFile=%UnZipFile:^)=^^)%"
	)
	rem !FilePath! !UnZipFolder!
	set "PathFilename=%Driver%!FilePath!Downloads\%AppName%\%Version%\%FileName%"
	rem 未被更改這時是%%
	set "InstallFilename=%PathFilename%"
	set "DownloadPath=%Driver%!FilePath!Downloads\%AppName%\%Version%\"

	rem 解壓縮後再執行安裝
	set "FileExtension=%FileName:~-3%"
	rem ====	不可含() 也不可加 "" 2024-10-11 21:11
	if /i %FileExtension% EQU zip (
		if defined UnZipFile (
			set "InstallFilename=%Driver%!FilePath!Downloads\%AppName%\%Version%\%UnZipFile%"
		)
	)	
	
	if defined UnZipFolder (
		set "UnZipPath=%Driver%!FilePath!Downloads\%AppName%\%Version%!UnZipFolder!"
	) else (
		set "UnZipPath=%Driver%!FilePath!Downloads\%AppName%\%Version%\"
	)

	set /a FileExist=0
	set /a Install=0

	set /a IsZip=0
	set /a IsUnZipFolder=0

	set /a IsCurl=0

	::	MediaFire
	set II=
	set Ihref=
	set Downloadhref=

	rem C:\Users\Public\Downloads\MicrosoftOffice
	set "ExtractPath=%PUBLIC%\Downloads\%Product_ID%\%Version%"
	set "xmlFile=%ExtractPath%\%Product_ID%.xml"
	set Input_run=
	set /a IsToRun=0
	set chcp_Code=
	set "PathFilename=%USERPROFILE%\Downloads\%FileName%"

	exit /b

:C2R-R2V-AIO
	curl.exe -LJR --url "https://github.com/abbodi1406/C2R-R2V-AIO/raw/refs/heads/master/C2R-R2V-AIO.cmd" -o "C2R-R2V-AIO.cmd" -k  --show-error --fail
	exit /b

:RunCurl
	rem bug
	rem ====----	curl.exe	:SetVariable	----	PathFilename
	if not defined Download (
		echo %ClolorRed_NT%Not defined Download%DefaultClolor%
	)

	rem ====----	MediaFire
	rem if defined MediaFire (
	rem 	goto RunMediaFire
	rem )

	rem ====	不可含()
	if not exist "%PathFilename%" (
		curl.exe -LJR --url "%Download%" -o "%PathFilename%" -k --show-error --fail
	)

	if %errorlevel% NEQ 0 (
		echo.%ClolorRed_BT%
		echo An curl error was found : "%Download%"
		echo.%DefaultClolor%
		pause
	)

	if exist "%PathFilename%" (
		echo Download: "%PathFilename%"
	 	dir "%pathFilename%" | findstr /I "%Filename%"
	)

	exit /b

:Checkdir
	rem ====----	https://stackoverflow.com/questions/18639663/how-to-pass-command-line-parameters-with-space-in-batch-file

	if exist "%*" (
		exit /b
	)
	if not exist "%*" (
		mkdir "%*"
	)
	if exist "%*" (
		echo %* Created
	)
	exit /b

:7z
	rem ====----	parameters 1 2 3 4
	rem ====	mode file outpath file
	if exist %2 (
		echo "%ProgramFiles%\7-Zip\7z.exe" %1 -y %2 -o%3 %4 -p%password% -aoa
		"%ProgramFiles%\7-Zip\7z.exe" %1 -y %2 -o%3 %4 -p%password% -aoa
	) else (
		echo %2
		goto End
	)
	exit /b

:IsAdmin
	reg.exe query "HKU\S-1-5-19\Environment" >nul
	if not %ERRORLEVEL% EQU 0 (
		echo 必須「以系統管理員身分執行」
		echo You must have administrator rights to continue ...
		pause & exit
	)
	exit /b

:End
	echo.
	rem echo %extractPath%
	if exist "%ExtractPath%\%Product_ID%.bat" (
		call Explorer.exe /root,"%extractPath%"
	) else (
		call Explorer.exe /root,"%FilePath%"
	)
	cd %Driver%%FilePath%
	%Driver%
	%ComSpec% /%EndCmd%